
#include"Tool.h"

//高位在前
uint16_t TOOL_Uint8ToUint16_L(uint8_t* input)
 {
	 uint16_t result;
	 result = input[0];
	 result <<= 8;
	 result |= input[1];
	 return result;
 }

//高位在前
 uint32_t TOOL_Uint8ToUint32_L(uint8_t* input)
 {
	 uint32_t result;
	 result = input[0];
	 result <<= 8;
	 result |= input[1];
	 result <<= 8;
	 result |= input[2];
	 result <<= 8;
	 result |= input[3];
	 return result;
 }

//高位在后
 uint16_t TOOL_Uint8ToUint16_H(uint8_t* input)
 {
	 uint16_t result;
	 result = input[1];
	 result <<= 8;
	 result |= input[0];
	 return result;
 }

//高位在后
uint32_t TOOL_Uint8ToUint32_H(uint8_t* input)
{
    uint32_t result;
    result = input[3];
    result <<= 8;
    result |= input[2];
    result <<= 8;
    result |= input[1];
    result <<= 8;
    result |= input[0];
    return result;
}

//高位在后
void TOOL_Uint16ToUint8_H(uint8_t* output , uint16_t input)
{
  output[0] = (uint8_t)input;
  output[1] = (uint8_t)(input>>8);
}

 //高位在后
void TOOL_Uint32ToUint8_H(uint8_t* output , uint32_t input)
{
  output[0] = (uint8_t)input;
  output[1] = (uint8_t)(input>>8);
  output[2] = (uint8_t)(input>>16);
  output[3] = (uint8_t)(input>>24);
}

  //高位在后
void TOOL_Uint16ToUint8_L(uint8_t* output , uint16_t input)
{
    output[1] = (uint8_t)input;
    output[0] = (uint8_t)(input>>8);
}

//高位在后
void TOOL_Uint32ToUint8_L(uint8_t* output , uint32_t input)
{
    output[3] = (uint8_t)input;
    output[2] = (uint8_t)(input>>8);
    output[1] = (uint8_t)(input>>16);
    output[0] = (uint8_t)(input>>24);
}

 
 union FloatToUint32
{
	uint32_t Udata;
	float Fdata;
};


float TOOL_Uint32ToFlaot(uint8_t* input)
{
	union FloatToUint32 ChangeUnion;
	ChangeUnion.Udata = input[3];
	ChangeUnion.Udata <<= 8;
	ChangeUnion.Udata |= input[2];
	ChangeUnion.Udata <<= 8;
	ChangeUnion.Udata |= input[1];
	ChangeUnion.Udata <<= 8;
	ChangeUnion.Udata |= input[0];
	return ChangeUnion.Fdata;
}


 void TOOL_FlaotToUint32(uint8_t* output , float input)
{
	union FloatToUint32 ChangeUnion;
	ChangeUnion.Fdata = input;
	output[0] = (uint8_t)ChangeUnion.Udata;
	output[1] = (uint8_t)(ChangeUnion.Udata >> 8);
	output[2] = (uint8_t)(ChangeUnion.Udata >> 16);
	output[3] = (uint8_t)(ChangeUnion.Udata >> 24);
}


